﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

namespace Acoris.Rendering
{
    /// <summary>
    /// 表示一段文本自然段
    /// </summary>
    public sealed class Paragraph : VisualElement, IEnumerable<TextRun>
    {
        private IList<TextRun>              m_textRunList;

        internal Paragraph()
        {
            m_textRunList = new List<TextRun>();
        }

        #region VisualElement Override

        internal override void CreateResources(IDrawingContext factory)
        {
            foreach(var textRun in m_textRunList)
            {
                textRun.CreateResources(factory);
            }
        }

        public override void Dispose()
        {
            foreach (var run in m_textRunList)
            {
                run?.Dispose();
            }
            m_textRunList = null;
        }

        internal override void Render(IDrawingContext drawingContext)
        {

        }

        #endregion

        #region IEnumerable<TextRun> 接口成员


        public IEnumerator<TextRun> GetEnumerator()
        {
            return this.m_textRunList.GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return this.m_textRunList.GetEnumerator();
        }

        #endregion

        #region Override

        /// <summary>
        /// 获取与当前对象等价的字符串形式
        /// </summary>
        /// <returns>返回与当前对象等价的字符串形式</returns>
        public override string ToString()
        {
            return base.ToString();
        }

        /// <summary>
        /// 获取当前对象与指定对象之间的等价性
        /// </summary>
        /// <param name="obj">指定要比较的对象</param>
        /// <returns>如果两个对象之间等价则返回true，否则返回false</returns>
        public override bool Equals(object obj)
        {
            return false;
        }

        /// <summary>
        /// 获取当前对象的哈希值
        /// </summary>
        /// <returns>返回当前对象的哈希值</returns>
        public override int GetHashCode()
        {
            return base.GetHashCode();
        }
        #endregion
    }
}
